def a(n):
    if n <= 1:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True


def b(w1, w2, w3):
    chisla = {"zero": "0","one": "1","two": "2","three": "3","four": "4","five": "5","six": "6","seven": "7","eight": "8","nine": "9"}
    num_str = chisla.get(w1, "") + chisla.get(w2, "") + chisla.get(w3, "")
    if not num_str.isdigit() or len(num_str) != 3:
        return "Wrong input"

    num = int(num_str)
    l = num - 1
    u = num + 1
    while True:
        if a(l):
            return l
        elif a(u):
            return u
        else:
            l -= 1
            u += 1


w1, w2, w3 = input("Введите числа: ").split()
result = b(w1, w2, w3)
print(result)